<%@page import="java.sql.*" %>
<%@page import="com.mysql.jdbc.*" %>
<%@page import="java.lang.*" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%
    String login = (String) session.getAttribute("login");
    if (!login.equals("true")) {
        response.sendRedirect("login.jsp");
        return;
    }
    response.setCharacterEncoding("utf-8");
%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script src="/zjcwkj/js/myjs.js"></script>
        <style>
            form {
                margin: 0;
            }
            textarea {
                display: block;
            }
        </style>
        <script charset="utf-8" src="editor/kindeditor-min.js"></script>
        <script charset="utf-8" src="editor/lang/zh_CN.js"></script>
        <script>
            var editor;
            KindEditor.ready(function(K) {
                editor = K.create('textarea[name="content"]', {
                    resizeType : 1,
                    allowPreviewEmoticons : false,
                    allowImageUpload : false,
                    items : [
                        'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                        'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
                        'insertunorderedlist', '|', 'emoticons', 'image', 'link']
                });
            });
        </script>
    </head>
    <body style="background-color: #D5EBFF;margin-top: 0px">
        <%

            String tempString = null;
            String idString = request.getParameter("id");
            if (idString == null) {
                idString = "1";
            }
            int id = Integer.parseInt(idString);
            String driverName = "com.mysql.jdbc.Driver";
            String userName = "root";
            String userPasswd = "1";
            String dbName = "zjcwkj";
            String dbTable;
            String SQL;
            String url = "jdbc:mysql://localhost/" + dbName + "?user=" + userName + "&password=" + userPasswd;
            Class.forName("com.mysql.jdbc.Driver");
            java.sql.Connection connection = DriverManager.getConnection(url);
            java.sql.Statement statement = connection.createStatement();
            ResultSet rs;
            switch (id) {
                case 1:
                    dbTable = "info";
                    SQL = "select home from " + dbTable;
                    rs = statement.executeQuery(SQL);
                    if (rs.next()) {
                        tempString = rs.getString(1);
                    }
        %>
        <form action="WriteDB?case=1&action=add" method="POST">
            <textarea name="content" style="width:700px;height:500px;visibility:hidden;"><%=tempString%></textarea>
            <input type="submit" value="提交" />
        </form>
        <%
                break;
            case 2:
                dbTable = "info";
                SQL = "select info from " + dbTable;
                rs = statement.executeQuery(SQL);
                if (rs.next()) {
                    tempString = rs.getString(1);
                }
        %>
        <form action="WriteDB?case=2&action=add" method="POST">
            <textarea name="content" style="width:700px;height:500px;visibility:hidden;"><%=tempString%></textarea>
            <input type="submit" value="提交" />
        </form>
        <%
                break;
            case 3:
                dbTable = "info";
                SQL = "select teacher from " + dbTable;
                rs = statement.executeQuery(SQL);
                if (rs.next()) {
                    tempString = rs.getString(1);
                }
        %>
        <form action="WriteDB?case=3&action=add" method="POST">
            <textarea name="content" style="width:700px;height:500px;visibility:hidden;"><%=tempString%></textarea>
            <input type="submit" value="提交" />
        </form>
        <%
                break;
            case 4:
                dbTable = "syllabus";
                SQL = "select * from " + dbTable;
                rs = statement.executeQuery(SQL);
        %>
        <table>
            <form id="form" action="WriteDB?case=4&action=add" encType="multipart/form-data"  method="POST">
                <%
                    while (rs.next()) {
                %>
                <tr>
                    <td>
                        <a href=<%= rs.getString("filename")%>><%=rs.getString("name")%></a>
                    </td>
                    <td>
                        <a href="WriteDB?case=4&action=delete&id=<%=rs.getString("syllabusid")%>" onclick="return confirm('确认删除？');">删除</a>
                    </td>
                    <td>
                        <p onclick="edit('<%=rs.getString("name")%>','<%=rs.getString("syllabusid")%>');" >修改</p>
                    </td>
                </tr>
                <%}%>
                <tr>
                    <td>
                        名称：<input id="name"  name="name" /> 
                    </td>
                    <td>
                        <input type="file" name="file" />
                    </td>
                    <td>
                        <input id="button" type="submit"  value="增加" />
                    </td>
                </tr>
        </table>
    </form>
    <%

            break;
        case 5:
            dbTable = "courseware";
            SQL = "select * from " + dbTable;
            rs = statement.executeQuery(SQL);
    %>
    <form id="form" action="WriteDB?case=5&action=add" encType="multipart/form-data" method="POST">
        <table border="1">
            <%
                while (rs.next()) {
            %>
            <tr>
                <td>
                    <%=rs.getString("name")%>
                </td>
                <td>
                    <a href="WriteDB?case=5&action=delete&id=<%=rs.getString("coursewareid")%>" onclick="return confirm('确认删除？');">删除</a>
                </td>

                <td>
                    <p onclick="edit('<%=rs.getString("name")%>','<%=rs.getString("coursewareid")%>');" >修改</p>
                </td>
            </tr>
            <%
                }
            %>
            <tr>
                <td>
                    名称：<input id="name" name="name" /> 
                </td>
                <td>
                    课件：<input type="file" name="couseware" />
                </td>
                <td>
                    教案：<input id="button" type="file" name="plan" /><input type="submit" value="增加"/>
                </td>
            </tr>
        </table>
    </form>
    <%
            break;
        case 6:
            dbTable = "video";
            SQL = "select * from " + dbTable;
            rs = statement.executeQuery(SQL);
    %>
    <form id="form" action="WriteDB?case=6&action=add" encType="multipart/form-data" method="POST">
        <table>
            <%
                while (rs.next()) {
            %>
            <tr>
                <td>
                    <p><%=rs.getString("name")%></p>
                </td>
                <td>
                    <p>
                        <a href="WriteDB?case=6&action=add" onclick="return confirm('确认删除？');">删除</a>
                    </p>
                </td>
                <td>
                    <p onclick="s('<%=rs.getString("name")%>','<%=rs.getString("speakername")%>','<%=rs.getString("videoid")%>');" >修改</p>
                </td>
            </tr>
            <%                        }
            %>
            <tr>
                <td>
                    <p>名称：<input id="name" name="name"/></p>
                </td>
                <td>
                    <p>主讲人：<input id="speaker" name="speaker"/></p>
                </td>
                <td>
                    <p><input type="file" name="file" /></p>
                </td>
                <td>
                    <p><input id="button" type="submit" value="增加"  /></p>
                </td>
            </tr>
        </table>
    </form>
    <%

            break;
        case 7:
            dbTable = "exercise";
            SQL = "select * from " + dbTable;
            rs = statement.executeQuery(SQL);
    %>
    <form id="form" action="WriteDB?case=7&action=add" encType="multipart/form-data" method="POST">
        <table>
            <%
                while (rs.next()) {
            %>
            <tr>
                <td>
                    <p><%=rs.getString("name")%></p>
                </td>
                <td>
                    <p>
                        <a href="WriteDB?case=7&id=<%=rs.getString("exerciseid")%>" onclick="return confirm('确认删除？');">删除</a>
                    </p>
                </td>
                <td>
                    <p onclick="edit('<%=rs.getString("name")%>','<%=rs.getString("exerciseid")%>');" >修改</p>
                </td>
            </tr>
            <%                        }
            %>
            <tr>
                <td>
                    <p>名称：<input id="name" name="name"/></p>
                </td>
                <td>
                    <p><input type="file" name="file" /></p>
                </td>
                <td>
                    <p><input id="button" type="submit" value="增加"  /></p>
                </td>
            </tr>
        </table>
    </form>
    <%

            break;
        case 8:
            dbTable = "practice";
            SQL = "select * from " + dbTable;
            rs = statement.executeQuery(SQL);
    %>
    <form action="WriteDB?case=8&action=add" id="form" encType="multipart/form-data" method="POST">
        <table>
            <%
                while (rs.next()) {
            %>
            <tr>
                <td>
                    <p><%=rs.getString("name")%></p>
                </td>
                <td>
                    <p>
                        <a href="WriteDB?case=8&id=<%=rs.getString("practiceid")%>" onclick="return confirm('确认删除？');">删除</a>
                    </p>
                </td>
                <td>
                    <p onclick="edit('<%=rs.getString("name")%>','<%=rs.getString("practiceid")%>');" >修改</p>
                </td>
            </tr>
            <%                        }
            %>
            <tr>
                <td>
                    <p>名称：<input id="name" name="name"/></p>
                </td>
                <td>
                    <p><input type="file" name="file" /></p>
                </td>
                <td>
                    <p><input id="button" type="submit" value="增加"  /></p>
                </td>
            </tr>
        </table>
    </form>
    <%

            break;

        case 9:
            dbTable = "info";
            SQL = "select material from " + dbTable;
            rs = statement.executeQuery(SQL);
            if (rs.next()) {
                tempString = rs.getString(1);
            }
    %>
    <form action="WriteDB?case=9&action=add" method="POST">
        <textarea name="content" style="width:700px;height:200px;visibility:hidden;"><%=tempString%></textarea>
        <input type="submit" value="提交" />
    </form>
    <%
            break;
        case 10:
            dbTable = "qa";
            SQL = "select * from " + dbTable + " where flag=1";
            rs = statement.executeQuery(SQL);

    %>
    <table border="1">
        <%
            while (rs.next()) {
        %>
        <tr>
            <td>
                <span>问题：<%=rs.getString("question")%></span>
            </td>
            <td>
                <span>回答：<%=rs.getString("anwser")%></span>
            </td>
            <td>
                <a href="WriteDB?case=10&action=delete&id=<%=rs.getString("qaid")%>">删除</a>
            </td>
        </tr>
        <%}
            SQL = "select * from " + dbTable + " where flag=0";
            rs = statement.executeQuery(SQL);
        %>
    </table>
    <%while (rs.next()) {%>

    <form action="WriteDB?case=10&id=<%=rs.getString("qaid")%>&action=anwser" method="POST">
        <p>问题：<%=rs.getString("question")%> <a href="WriteDB?case=10&action=delete&id=<%=rs.getString("qaid")%>">删除</a></p>
        <textarea name="content" style="width:700px;height:200px;"></textarea>
        <input type="submit" value="提交" />
    </form>

    <%}
                break;
            default:
                break;
        }
    %>

</body>
</html>
